home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8870 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.0 KB

  1. From: LittleGuyRascal@msn.com (Gregory Saxton)
  2. Subject: RE: Passing functions as parameters... inconsistent behaviour
  3. Date: 27 Feb 96 03:01:32 -0800
  4. References: <4glbau$tge@inet.up.ac.za>
  5. Message-ID: <00001a81+0000a88d@msn.com>
  6. Path: news.msn.com!msn.com
  7. Newsgroups: comp.lang.c++
  8. Organization: The Microsoft Network (msn.com)
  9.  
  10. Cool problem.
  11.  
  12. The reason this is happening has nothing to do with functions as parameters.
  13.  
  14. The function test is prototyped as type void requiring one parameter 
  15. - a pointer to a function which returns a float - there is no arument 
  16. list specifying int or float so the compiler defaults to a parameter 
  17. of int for passedfunc.
  18.  
  19. When you change the declaration of function passed to have one 
  20. parameter of type float and not int you are lucky to compile because 
  21. you are multiply defining a function.  If this were a C++ application 
  22. the link step would fail with an unresolved external.
  23.  
  24. Change the prototype of function test to be void test(float 
  25. (*passedfunc)(float) )
  26. and your are in business!
  27.  
  28. clear as mud?  Good Luck!
  29.